# Please install OpenAI SDK first: `pip3 install openai`

from openai import OpenAI
import time


my_key = "sk-b9f648c06fff48ae86a07e69c1fb51e8"
deepseek_url = "https://api.deepseek.com"


def deepseek_chat(input):
    client = OpenAI(api_key = my_key, base_url = deepseek_url)
    # print(client.models.list())
    response = client.chat.completions.create(
        model="deepseek-chat",
        messages=[
            {"role": "system", "content": "You are a helpful assistant"},
            {"role": "user", "content": input},
        ],
        stream=False
    )
    print(response.choices[0].message.content)
    

if __name__=="__main__":
    
    my_question = "hi"
    
    strat = time.time()
    deepseek_chat(my_question)
    end = time.time()

    print(f"deepseek_chat 此次调用花费时间为：{(end-strat):.4f}秒")



# for backward compatibility, you can still use `https://api.deepseek.com/v1` as `base_url`.


# def get_model_list(api_key):

#     url = "https://api.deepseek.com/models"

#     payload = {}
#     headers = {
#         'Accept': 'application/json',
#         'Authorization': "Bearer {}".format(api_key)
#     }

#     response = requests.request("GET", url, headers=headers, data=payload)
#     print(response.text)
    



